package com.zsg.anim;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {
    ImageView imageView;
    ImageView imageView333;
    ImageView imageView555;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.imageView);
        //imageView2= (ImageView) findViewById(R.id.imageView2);
        Animation anmi2 = AnimationUtils.loadAnimation(this, R.anim.scale);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        switch (id) {
            case R.id.action_alpha:
                showAnimaon();
                break;
            case R.id.action_next:
                doNext();
                break;

        }

        return true;
    }

    private void doNext() {
        Intent intent = new Intent(this, NextActivity.class);
        startActivity(intent);

        //转场动画   参数1 进场动画   参数2 离场动画
        overridePendingTransition(R.anim.right, R.anim.left);
    }

    private void showScale() {
        Animation anmi2 = AnimationUtils.loadAnimation(this, R.anim.scale);
        imageView.startAnimation(anmi2);
    }

    private void showRotate() {
        //xml文件创建
        Animation anmi = AnimationUtils.loadAnimation(this, R.anim.rotate);
        imageView.startAnimation(anmi);

        //Animation anmi2= AnimationUtils.loadAnimation(this,R.anim.alpha);
        //imageView2.setVisibility(View.VISIBLE);
        //imageView2.setAnimation(anmi2);

    }

    private void showAnimaon() {

        //1 代码方式
        AlphaAnimation animation = new AlphaAnimation(1f, 0f);

        //设置动画持续时间
        animation.setDuration(2000);

        //设置重复模式  反转/重新开始
        animation.setRepeatMode(Animation.REVERSE);

        //设置重复次数  无限
        animation.setRepeatCount(Animation.INFINITE);

        //imageView.startAnimation(animation);

        //xml文件创建
        Animation anmi2 = AnimationUtils.loadAnimation(this, R.anim.myanim);
        imageView.startAnimation(anmi2);

    }
}
